﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Common;
using RegisterationCommon.Education;
using RegisterationCommon.School;
using System.IO;
namespace RegisterationSystem.Space_School
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //登录
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //判断用户密码是否为空
            if (this.txtname.Text == "" || this.txtpwd.Text == "")
            {
                Message.Send(10015);
                return;
            }
            //判断验证码是否正确
            if (Convert.ToString(Session["RBVerifiCode"]).ToLower() != this.VerifCode.Text.ToLower())
            {
                Message.Send(10016);
                return;
            }
            //判断密码是否正确
            if (!SchoolAccount.Current.Login(this.txtname.Text.ToLower(), BaseLibrary.ConvertToMD5(this.txtpwd.Text.ToLower())))
            {
                Message.Send(10017);
                return;
            }
            if (SchoolAccount.Current.IsDisable)
            {
                Message.Send(10018);
                return;
            }
            DirectoryInfoList();
            Message.Send(10004);
        }
        void DirectoryInfoList()
        {
            ExcelHelper excel = new ExcelHelper();
            excel.CreateDirectory(Server.MapPath(@"..\StudentInfoToExcel\"));
            int day = 0;
            DirectoryInfo theFolder = new DirectoryInfo(Server.MapPath(@"..\StudentInfoToExcel\"));
            if (theFolder.GetFiles()!= null)
            {
                FileInfo[] dirInfo = theFolder.GetFiles();
                //遍历文件夹
                foreach (FileInfo NextFile in dirInfo)
                {
                    string filename = NextFile.Name;
                    string[] Date = filename.Split('_');
                    if (Date.Length > 1)
                    {
                        string strTimeNow = DateTime.Now.ToString("yyyyMMdd");
                        int d1 = int.Parse(Date[1]);
                        int d2 = int.Parse(strTimeNow);
                        int ND = d2 - d1;
                        day = ND;
                        if (day >= 1)
                        {
                            File.Delete(Server.MapPath(@"..\StudentInfoToExcel\" + filename));
                        }
                    }
                }
            }
        }
    }
}